*************************************************************************************************
*																								*
*						Flexible Wages, Bargaining, and The Gender Gap							*
*						Barbara Biasi and Heather Sarsons										*
*						Paper Tables															*
*																								*
*************************************************************************************************

clear all
set more off
set matsize 11000
set maxvar 32000


global user = 2 // 1 = Heather, 2 = Barbara

if $user == 1 {
cd "/Users/sarsons/Dropbox/wisconsin_women/data"
global tab = "/Users/sarsons/Dropbox/wisconsin_women/draft/tex/QJE_resubmission/QJE_files/tables"
global out = "/Users/sarsons/Dropbox/wisconsin_women/out"
global do = "/Users/sarsons/Dropbox/wisconsin_women/do"
global RA = "/Users/sarsons/Dropbox/wisconsin_women/do/calvin"
}
if $user == 2 {
cd "~/Dropbox/Research/wisconsin_women/data"
global tab = "~/Dropbox/Research/wisconsin_women/draft/tex/QJE_resubmission/QJE_files/tables"
global out = "~/Dropbox/Research/wisconsin_women/out"
global do = "~/Dropbox/Research/wisconsin_women/do"
global RA = "~/Dropbox/Research/wisconsin_women/do/calvin"
}

* Yale colors
global yaleblue = "0 53 107"
global ylb = "40 109 192"
global yo = "189 83 25"
global ylight = "217 233 242"
global graph = "xlabel(,grid glp(dot) glc(gs10) tlc(gs10)) ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"
global graphbar = "ylabel(,grid glp(dot) glc(gs10) tlc(gs10)) plotregion(lp(blank))"


do $do/QJE_R1/preamble_revision.do
replace logsalary = logsalary * 100
	global itt = "i.dist_itt i.dist_itt#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	global expD = "i.district_code i.district_code#i.postexp i.district_code#i.totalexp i.district_code#i.totalexp#i.postexp i.district_code#i.master i.district_code#i.master#i.postexp i.district_code#i.phd i.district_code#i.phd#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp i.year i.year##i.expire"
	g reltime = year-extension
	g endtime = 1 if reltime==3
	g starttime = 1 if reltime==-3
	bys id: egen fullstart = max(starttime) 
	by id: egen fullend = max(endtime)
	g balanced3 = (fullstart==1&fullend==1)
	drop endtime starttime fullstart fullend	
	g district2010 = district_code if year==2010
	bys id: egen dist_itt = max(district2010)
	drop district2010
	tempvar x
	g `x' = entry == 1 & totalexp == 1 & year <= 2011
	bysort id: egen entry_pre = max(`x')
keep if timex > -6

*-------------------------> 		Main file		<-------------------------*


*--> Table 1: Summary stats
preserve
	bysort id: egen ever_moves = max(mover_d)
	gen age = year - birth
	gen fulltime = fte >= 100
	replace fulltime = . if fte == .
	replace salary_n = salary_n / 1000
	label variable totalexp 	"Experience (yrs)"
	label variable age 			"Age"
	label variable ba 			"BA"
	label variable master 		"Master"
	label variable phd 			"PhD"
	label variable salary_n 	"Salary (\textdollar 1,000)"
	label variable va_s			"Value-added"
	label variable elem			"Elementary"
	label variable middle		"Middle"
	label variable high			"High"
	label variable math			"Math"
	label variable science		"Science"
	label variable reading		"Reading"
	label variable ever_moves	"Ever moves"
	label variable exit 		"Leaves sample"
	label variable fte			"Full-Time Equivalents"
	label variable fulltime		"Full-Time"
	global var = "totalexp age va_s salary_n fte fulltime ever_moves exit  ba master phd elem middle high math science reading"
	capt label define female 0	"Males" 1 "Females"
	label values female female


	eststo t1: estpost ttest  $var if post == 0, by(female)
	eststo t2: estpost ttest  $var if post == 1, by(female)
	esttab t1 t2	using "$tab/sumstats_teachers_repl.csv", csv plain nonum ///
					cells("mu_1(fmt(a2)) mu_2(fmt(a2)) b(fmt(a2)star)" ". . se(par)") star(* 0.10 ** 0.05 *** 0.01) ///
					main(mean) aux(sd) nonote unstack nogaps label collabels("Males" "Females" "Diff.") ///
					mtitle("\specialcell{2007-2011}" "\specialcell{2012-2016}") refcat(bachelor "\emph{\underline{Highest education}}" elem "\emph{\underline{Grade level}}" mathematics "\emph{\underline{Subject}}", nolabel) replace 
restore

		
**--> Table 2: Baseline estimates of the gender gap
eststo r1: reghdfe logsalary $tag_exp female female_postexp, a($exp) vce(cluster district_code)
preserve
	forvalues n = 1/5 {
	gen female_postext`n' = female * ((year - expire) == `n')
	label var female_postext`n' "Female $\times$ `n' Year(s) Post"
	}
	eststo r2: reghdfe logsalary $tag_exp female female_postext1 female_postext2 female_postext3 female_postext4 female_postext5, a($exp) vce(cluster district_code)
restore
eststo r3: reghdfe logsalary $tag_exp female female_postext, a($exp  i.extension##i.year) vce(cluster district_code)
preserve
	forvalues n = 1/5 {
	gen female_postext`n' = female * ((year - extension) == `n')
	label var female_postext`n' "Female $\times$ `n' Year(s) Post"
	}
	eststo r4: reghdfe logsalary $tag_exp female female_postext1 female_postext2 female_postext3 female_postext4 female_postext5, a($exp i.extension##i.year) vce(cluster district_code)
restore
eststo r5: ivreghdfe logsalary $tag_exp female (female_postext = female_postexp), a($exp i.extension##i.year) cluster(district_code)
preserve
	forvalues n = 1/5 {
	gen female_postext`n' = female * ((year - extension) == `n')
	gen female_postexp`n' = female * ((year - expire) == `n')
	label var female_postexp`n' "Female $\times$ `n' Year(s) Post"
	label var female_postext`n' "Female $\times$ `n' Year(s) Post"
	}
	eststo r6: ivreghdfe logsalary $tag_exp female (female_postext1 female_postext2 female_postext3 female_postext4 female_postext5 = female_postexp1 female_postexp2 female_postexp3 female_postexp4 female_postexp5), a($exp i.extension##i.year) cluster(district_code)
restore

forvalues n = 1/5 {
gen female_postext`n' = female * ((year - extension) == `n')
label var female_postext`n' "Female $\times$ `n' Year(s) Post"
}
esttab	r3 r4 r1 r2 r5 r6 using "$tab/gap_repl.csv"	///
		, b(3) se(3) unstack csv plain nonote label replace se keep(female female_postexp female_postext female_postext1 female_postext2 female_postext3 ///
		female_postext4 female_postext5) ///
		obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("Extensions" "Expirations" "2SLS, Extensions" , pattern(1 0 1 0 1)  ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
		nomtitle indicate("Controls = Ed" ///
		" Yr $\times$ Exp yr = Yr")  ///
		noobs frag substitute(\_ _) ///
		stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
		

		
**--> Table 3: Gender gap, by Schedule-no schedule districts
preserve
	gen female_pp = female * pp
	gen female_pp_postext = female * pp * postext
	label var female_pp "Female $\times$ No sched"
	label var female_pp_postext "Female $\times$ No sched $\times$ Post"
	capt gen timex = year - ext
	gen expclass = totalexp
	replace expclass  = 40 if expclass > 40 & expclass != .
	qui tab expclass
	forvalues e = 1 / `r(r)' {
	*local z = 2 * `e'
	local z = `e'
	gen fem_exp`z' =  female * (expclass == `z')
	gen post_exp`z' =  postext * (expclass == `z')
	gen post_exp_pp`z' =  postext * (expclass == `z') * pp
	gen fem_post_exp`z' =  female * postext * (expclass == `z')
	gen fem_post_exp_pp`z' =  female * postext * (expclass == `z') * pp
	replace fem_exp`z' = . if expclass == .
	replace post_exp`z' = . if expclass == .
	replace post_exp_pp`z' = . if expclass == .
	replace fem_post_exp`z' = . if expclass == .
	}
	gen A = 0
	order fem_exp*, last
	order post_exp*, last
	order fem_post_exp*, last
	gen master_  = 1 - master

	eststo r1: reghdfe logsalary $tag_exp female female_postext if pp == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r2: reghdfe logsalary $tag_exp female female_postext if pp == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r3: reghdfe logsalary $tag_exp female female_postext female_pp female_pp_postext, a($exp_pp i.extension##i.year##i.pp) vce(cluster district_code)
/*
	eststo r1: reghdfe logsalary $tag_exp female female_postext if pp == 1, a(i.district_code i.district_code#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.middle i.middle#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp  i.year i.extension##i.year) vce(cluster district_code)
	eststo r2: reghdfe logsalary $tag_exp female female_postext if pp == 0, a(i.district_code i.district_code#i.postexp i.totalexp i.totalexp#i.postexp i.master i.master#i.postexp i.phd i.phd#i.postexp i.middle i.middle#i.postexp i.high i.high#i.postexp i.math i.math#i.postexp  i.year i.extension##i.year) vce(cluster district_code)
	eststo r3: reghdfe logsalary $tag_exp female female_postext female_pp female_pp_postext, a(i.district_code i.district_code#i.postexp i.totalexp i.totalexp#i.postexp i.totalexp#i.pp i.totalexp#i.postexp#i.pp i.master i.master#i.postexp i.master#i.pp i.master#i.postexp#i.pp i.phd#i.pp i.phd#i.postexp#i.pp i.middle i.middle#i.postexp i.middle#i.pp i.middle#i.postexp#i.pp i.high i.pp#i.high i.high#i.postexp i.pp#i.high#i.postexp i.math i.math#i.pp i.math#i.postexp i.math#i.postexp#i.pp  i.year i.pp#i.year i.extension##i.year##i.pp) vce(cluster district_code)
*/
	global expcontr = "post_exp2 post_exp5-post_exp40  fem_exp2 fem_exp5-fem_exp40  fem_post_exp2 fem_post_exp5-fem_post_exp40"
	global expcontr_pp = "post_exp2 post_exp5-post_exp40  fem_exp2 fem_exp5-fem_exp40  fem_post_exp2 fem_post_exp5-fem_post_exp40 post_exp_pp2 post_exp_pp5-post_exp_pp40 fem_post_exp_pp2 fem_post_exp_pp5-fem_post_exp_pp40"

	eststo r4: reghdfe logsalary $tag_exp A female female_postext c.master_#c.female c.master_#c.postext c.master_#c.female#c.postext $expcontr if timex > -7 & pp == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r5: reghdfe logsalary $tag_exp A female female_postext c.master_#c.female c.master_#c.postext c.master_#c.female#c.postext $expcontr if timex > -7 & pp == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r6: reghdfe logsalary $tag_exp A female female_postext female_pp female_pp_postext c.master_#c.female#c.pp c.master_#c.female c.master_#c.postext c.master_#c.pp#c.postext c.master_#c.female#c.postext c.master_#c.female#c.postext#c.pp  $expcontr_pp if timex > -7, a($exp_pp pp##i.extension##i.year) vce(cluster district_code)
	esttab	r1 r2 r3 r4 r5 r6 using "$tab/gap_bypp_ext_repl.csv"	///
			, b(3) se(3) csv plain unstack nonote label replace se keep(female female_postext female_pp female_pp_postext) ///
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) ///
			mgroups("Baseline" "Gender-specific schedule, 3-4 yrs seniority, ", pattern(1 0 0 1 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span}))  ///
			mtitle("No schedule" "Schedule" "Diff" "No schedule" "Schedule" "Diff") ///
			indicate("Controls = Ed" ///
			" Yr $\times$ Exp yr = Yr" "Exper * Female * Post Ext = A") noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
restore
		

*--> Table 4: Gender gap, by management gender		
preserve
drop maleprinc* malesuper*
rename male_princ_year maleprinc 
rename male_super_year malesuper
	gen female_postext_malep = female * postext * maleprinc
	gen postext_malep = postext * maleprinc
	gen female_malep = female * maleprinc
	
	gen female_postext_males = female * postext * malesuper
	gen postext_males = postext * malesuper
	gen female_males = female * malesuper
	egen schid = group(district2011 school2011)


	label var maleprinc "Male princ"
	label var malesuper "Male super"
	label var female_malep "Female $\times$ Male princ"
	label var female_males "Female $\times$ Male super"
	label var postext_malep "Post $\times$ Male princ"
	label var postext_males "Post $\times$ Male super"
	label var female_postext_malep "Female $\times$ Male princ $\times$ Post"
	label var female_postext_males "Female $\times$ Male super $\times$ Post"
	global exp_malep = "i.district_code i.maleprinc i.district_code#i.postexp i.totalexp i.maleprinc#i.totalexp i.totalexp#i.postexp i.maleprinc#i.totalexp#i.postexp i.masterup i.maleprinc#i.masterup i.masterup#i.postexp i.maleprinc#i.masterup#i.postexp i.high i.maleprinc#i.high i.high#i.postexp i.maleprinc#i.high#i.postexp i.year i.maleprinc#i.year i.year#i.expire i.maleprinc#i.year#i.expire"
	global exp_males = "i.district_code i.malesuper i.district_code#i.postexp i.totalexp i.malesuper#i.totalexp i.totalexp#i.postexp i.malesuper#i.totalexp#i.postexp i.masterup i.malesuper#i.masterup i.masterup#i.postexp i.malesuper#i.masterup#i.postexp i.high i.malesuper#i.high i.high#i.postexp i.malesuper#i.high#i.postexp i.year i.malesuper#i.year i.year#i.expire i.malesuper#i.year#i.expire"
	eststo r1princ: reghdfe logsalary $tag_exp female female_postext if maleprinc == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r2princ: reghdfe logsalary $tag_exp female female_postext if maleprinc == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r3princ: reghdfe logsalary $tag_exp female female_postext postext_malep maleprinc female_malep female_postext_malep, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r4super: reghdfe logsalary $tag_exp female female_postext if malesuper == 1, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r5super: reghdfe logsalary $tag_exp female female_postext if malesuper == 0, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r6super: reghdfe logsalary $tag_exp female female_postext postext_males malesuper female_males female_postext_males, a($exp i.extension##i.year) vce(cluster district_code)


	esttab	r1princ r2princ r3princ r4super r5super r6super using "$tab/gap_bymanagement_repl.csv"	///
			, b(3) se(3) unstack csv plain nonote label replace se keep(female female_postext female_malep female_postext_malep female_males female_postext_males) ///
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("Principal" "Superintendent", pattern(1 0 0 1 0 0)  ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
			mtitle("Male" "Female" " " "Male" "Female" " ") ///
			indicate("Controls = Edexp" "Yr $\times$ Exp yr = Yr")  ///
			noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
restore



*--> Table 7: Gap, controlling for VA
preserve
	su va_s, det
	replace va_s = . if va_s > `r(p99)' & va_s != .
	su va_s, det
	replace va_s = . if va_s < `r(p1)' & va_s != .
	su va_s, det
	gen vast = (va_s - `r(mean)') / `r(sd)'
	gen female_va = female*vast
	gen va_postext = vast * postext
	gen female_va_postext = female * vast * postext
	gen male_va_postext = (1 - female) * vast * postext

	label var female "Female"
	label var female_va "Female $\times$ VA"
	label var vast "VA (sd)"
	label var va_postext "VA $\times$ Post Extension"
	label var female_va_postext "Female $\times$ VA $\times$ Post Extension"
	label var male_va_postext "Male $\times$ VA $\times$ Post Extension"

	eststo r1: reghdfe logsalary $tag_exp female female_postext if va_s != ., a($exp i.extension##i.year) vce(cluster district_code)
	eststo r1a: reghdfe logsalary $tag_exp female female_postext if vast == ., a($exp i.extension##i.year) vce(cluster district_code)
	eststo r2: reghdfe logsalary $tag_exp female female_postext vast va_postext, a($exp i.extension##i.year) vce(cluster district_code)
	eststo r3: reghdfe logsalary $tag_exp female female_postext vast female_va male_va_postext female_va_postext, a($exp i.extension##i.year) vce(cluster district_code)
	disp _b[vast] + _b[female_va] 
	test _b[vast] + _b[vast] = 0
	*disp _b[va_postext] + _b[female_va_postext] 
	*test _b[va_postext] + _b[female_va_postext] = 0
esttab	 r1a r1 r2 r3  using "$tab/gap_byva_repl.csv"	///
			, b(3) se(3) unstack csv plain nonote label replace se keep(female female_postext female_va vast va_postext male_va_postext female_va_postext) ///
			indicate("Controls = Edexp" "Yr $\times$ Exp yr = Yr")  ///
			mgroups("Without VA" "With VA", pattern(1 1 0 0) ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///		
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) ///
			nomtitle noobs frag substitute(\_ _) ///
			stats(N N_clust, fmt(0 0) labels(`"N"' `"\# districts"'))
restore

*--> Table 8: Mobility
preserve
	sort district_code
	merge m:1 district_code using district_county_cz.dta
	drop if _m==2
	drop _m	
	sort id year
	by id: g moves_within_cz = 1 if (cz==cz[_n-1]) & mover_d == 1
	replace moves_within_cz=0 if moves_within_cz==.	
	by id: replace moves_within_cz=. if _n==1
	replace moves_within_cz=0 if mover_d==0	
	gen moves_x_cz = mover_d == 1 & moves_within_cz == 0
	replace moves_x_cz = . if moves_within_cz == . | mover_d == .
	gen D = 0
	gen X = 0
	gen Y = 0
	eststo r1: reg mover_d female postext female_postext, cluster(district_code)
	qui sum mover_d if female == 0 & e(sample)
	estadd scalar ymean = `r(mean)'
	eststo r2: reghdfe mover_d female postext female_postext D Y, a(district_code year) cluster(district_code)
	qui sum mover_d if female == 0 & e(sample)
	estadd scalar ymean = `r(mean)'
	eststo r3: reghdfe mover_d female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
	qui sum mover_d if female == 0 & e(sample)
	estadd scalar ymean = `r(mean)'
	eststo r4: reghdfe moves_within_cz female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
	qui sum moves_within_cz if female == 0 & e(sample)
	estadd scalar ymean = `r(mean)'
	eststo r5: reghdfe moves_x_cz female postext female_postext D Y X if timex > -7, a(district_code year i.totalexp i.ba i.master i.phd i.year) cluster(district_code)
	qui sum moves_x_cz if female == 0 & e(sample)
	estadd scalar ymean = `r(mean)'
	esttab r1 r2 r3 r4 r5 using $tab/mobility_all_repl.csv, b(4) se(4) unstack nonote csv plain label replace se keep(female postext female_postext) ///
			obslast starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) mgroups("All moves" "Within CZ" "Across CZ" , pattern(1 0 0 1 1)  ///
			prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) ///
			nomtitle indicate("District FE = D" "Year FE = Y" "Exp, edu FE = X")  ///
			noobs frag substitute(\_ _) stats(N N_clust ymean, fmt(0 0 4) labels(`"N"' `"\# districts"' `"Mean of dep. var."'))
restore



*--> Table 5: Survey, means
global options "replace label noobs nolines frag nonum nomtitles collabels(none) starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01)"
global optionsapp "append label noobs nolines frag nonum nomtitles collabels(none) starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01)"
global options2 "replace label noobs nolines frag starlevel(\$^*\$ .1 \$^{**}\$ .05 \$^{***}\$ .01)"
global cells "mu_1(fmt(3))  mu_2(fmt(3)) b(star fmt(3)) se(fmt(3) par)"
use survey.dta, clear
replace gender = 1 - gender
use survey.dta, clear
replace gender = 1 - gender
tab age, gen(Age)
label var Age1 "26-30"
label var Age2 "31-35"
label var Age3 "36-40"
label var Age4 "41-45"
label var Age5 "46-50"
label var Age6 "51-55"
label var Age7 "56 and above" 
label var Age8 "less than 25"

* Age
eststo r1: qui estpost ttest Age8 Age1 Age2 Age3 Age4 Age5 Age6 Age7, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $options


* Work in other industries
label var workinotherind "I worked in other industries"
gen know_neg_yes = regexm(know_neg,"Yes")
label var know_neg_yes "I know someone who negotiated their pay"
gen know_colleague_salary_yes = regexm(know_colleague_salary,"Yes")
label var know_colleague_salary_yes "I know my colleagues' pay"
eststo r1: qui estpost ttest workinotherind know_neg_yes know_colleague_salary_yes, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp

* Negotiation vars
foreach var in negotiate_prev negotiate_current_beg negotiate_current_after {
gen `var'_yes = regexm(`var',"Yes")
replace `var'_yes = . if regexm(`var',"NA")
}
label var negotiate_prev_yes "w/prev employer"
label var negotiate_current_beg_yes "w/current employer, at start"
label var negotiate_current_after_yes "w/current employer, after start"
eststo r1: qui estpost ttest negotiate_*_yes, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp

* Success of negotiations, for the yes
foreach var in negotiate_prev negotiate_current_beg negotiate_current_after {
gen `var'_succ = regexm(`var',", success")
replace `var'_succ = . if regexm(`var',"No") | regexm(`var',"NA")
}
label var negotiate_prev_succ " w/prev employer"
label var negotiate_current_beg_succ "w/current employer, at start"
label var negotiate_current_after_succ "w/current employer, after start"
eststo r1: qui estpost ttest *_succ, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp

* Reason for not negotiating, for the nos
foreach var in noneg_beg noneg_after {
label var `var'_notpossible "it was not possible" 
label var `var'_notcomf "I was not comfortable doing so" 
label var `var'_useless "It was useless"
label var `var'_backlash "I feared backlash"
label var `var'_satisfied "I was satisfied w/pay"
label var `var'_didntknow "I didn't know it was possible"
drop `var'_didntknow
}
eststo r1: qui estpost ttest noneg_beg_*, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp
eststo r1: qui estpost ttest noneg_after_*, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp


* Likelihood of future negotiations
label var likelihood_salary_neg "salary"
label var likelihood_class_neg "classroom assignment"
label var likelihood_nonteach_neg "non-teaching duties"
eststo r1: qui estpost ttest likelihood_salary_neg likelihood_class_neg likelihood_nonteach_neg, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp


* By Gender principal
preserve
use administrators.dta, clear
keep if position == 51 & year == 2016
rename female female_princ
collapse (max) female_princ, by(district_code)
sort district_code
save temp.dta, replace
restore
sort district
merge m:1 district using temp.dta
drop if _m == 2
drop _m
preserve
use administrators.dta, clear
keep if position == 5 & year == 2016
rename female female_super
collapse (max) female_super, by(district_code)
sort district_code
save temp.dta, replace
restore
sort district
merge m:1 district using temp.dta
drop if _m == 2
drop _m

eststo r1: qui estpost ttest negotiate_current_beg_yes negotiate_current_after_yes if female_super == 0, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp
eststo r1: qui estpost ttest negotiate_current_beg_yes negotiate_current_after_yes if female_super == 1, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp

eststo r1: qui estpost ttest likelihood_salary_neg likelihood_class_neg likelihood_nonteach_neg if female_super == 0, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp
eststo r1: qui estpost ttest likelihood_salary_neg likelihood_class_neg likelihood_nonteach_neg if female_super == 1, by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("$cells") $optionsapp


* People skills
gen conf = regexm(confident_talking,"Yes")
gen sign = regexm(subtle_signals,"Agree")
gen feel = regexm(read_feelings,"Agree")
gen ppl = regexm(people_skills,"Agree")
gen perf = regexm(rate_perf,"Above")
replace perf = regexm(rate_perf,"Average")
label var conf "I am confident talking to people I don't know"
label var sign "I can read subtle signals"
label var feel "I can read people's feelings"
label var ppl "I have good people's skills"
label var perf "My performance is above the mean"
eststo r1: qui estpost ttest conf sign feel ppl perf, by(gender)
esttab r1 using "$tab/survey_tab.tex",  cells("$cells") $optionsapp 

preserve
label var conf "N (teachers)"
eststo r1: qui estpost ttest conf , by(gender)
esttab r1 using "$tab/survey_tab.csv", csv plain  cells("N_1(fmt(0))  N_2(fmt(0)) sd_1(fmt(3) par) N(fmt(0))") $options 
restore


*-- Table 6: Survey baseline regressions
replace gender = 1 - gender

* balance sample
qui reg gender negotiate_prev_yes negotiate_current_beg_yes negotiate_current_after_yes /// 
		likelihood* Age* conf sign feel ppl perf workinother know_*_yes
gen sample = e(sample)		
global controls = "Age* conf sign feel ppl perf workinotherind know_*_yes"
label var gender "Female"
gen D = 0
gen fem_femsuper = gender * female_super
label var female_super "Female super"
label var fem_femsuper "Female * F super"

replace perf = regexm(rate_perf,"Average")
label var conf "I am confident talking to people I don't know"
label var sign "I can read subtle signals"
label var feel "I can read people's feelings"
label var ppl "I have good people's skills"
label var perf "My performance is above the mean"

* p(negotiate)
eststo r1: areg negotiate_current_beg_yes gender $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_beg_yes if gender == 0
estadd scalar ymean = `r(mean)'

eststo r2: areg negotiate_current_beg_yes gender fem_femsuper $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_beg_yes if gender == 0 & female_super == 0
estadd scalar ymean_male = `r(mean)'
qui sum negotiate_current_beg_yes if gender == 0 & female_super == 1
estadd scalar ymean_female = `r(mean)'

eststo r3: areg negotiate_current_after_yes gender $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_after_yes if gender == 0
estadd scalar ymean = `r(mean)'

eststo r4: areg negotiate_current_after_yes gender fem_femsuper $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_after_yes if gender == 0 & female_super == 0
estadd scalar ymean_male = `r(mean)'
qui sum negotiate_current_after_yes if gender == 0 & female_super == 1
estadd scalar ymean_female = `r(mean)'

eststo r5: areg likelihood_sal gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum likelihood_sal if gender == 0
estadd scalar ymean = `r(mean)'

eststo r6: areg likelihood_sal gender fem_femsuper $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum likelihood_sal if gender == 0 & female_super == 0
estadd scalar ymean_male = `r(mean)'
qui sum likelihood_sal if gender == 0 & female_super == 1
estadd scalar ymean_female = `r(mean)'

eststo r7: areg likelihood_class gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum likelihood_class if gender == 0
estadd scalar ymean = `r(mean)'

eststo r8: areg likelihood_nont gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum likelihood_nont if gender == 0
estadd scalar ymean = `r(mean)'

esttab r1 r2 r3 r4 r5 r6 r7 r8 using "$tab/survey_reg_neg_repl.csv", b(3) se(3) keep(gender fem_femsuper) $options2 ///
		indicate("Controls = conf") csv plain  mgroups("Current employer" "Likelihood future negotiations", pattern(1 0 0 0 1 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) stats(N ymean, fmt(0 3) ///
		 labels(`"N"' `"Y mean, males"')) mtitle("At start" "At start" "After" "After" "Salary" "Salary" "Classroom assgn" 			"Non-teaching duties")


* p(success|negotiate) and p(reasons)
eststo r1: areg negotiate_current_beg_succ gender $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_prev_succ if gender == 0
estadd scalar ymean = `r(mean)'

preserve
replace negotiate_current_beg_succ = 0 if negotiate_current_beg_yes == 0
eststo r2: areg negotiate_current_beg_succ gender $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'
restore
eststo r3: areg negotiate_current_beg_succ gender fem_femsuper $controls D if sample == 1, cluster(district_code) a(district_code)
qui sum negotiate_current_beg_succ if gender == 0
estadd scalar ymean = `r(mean)'


preserve
keep if negotiate_current_after_yes == 0
eststo r4: areg noneg_after_notpossible gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_notpossible if gender == 0
estadd scalar ymean = `r(mean)'
eststo r5: areg noneg_after_notcomf gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_notcomf if gender == 0
estadd scalar ymean = `r(mean)'
eststo r6: areg noneg_after_useless gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_useless if gender == 0
estadd scalar ymean = `r(mean)'
eststo r7: areg noneg_after_backlash gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_backlash if gender == 0
estadd scalar ymean = `r(mean)'
eststo r8: areg noneg_after_satisfied gender $controls if sample == 1, cluster(district_code) a(district_code)
qui sum noneg_after_satisfied if gender == 0
estadd scalar ymean = `r(mean)'
restore
esttab r1 r2 r3 r4 r5 r6 r7 r8  using "$tab/survey_reg_reasons_repl.csv", b(3) se(3) csv plain keep(gender fem_femsuper) $options2 ///
		indicate("Controls = conf") ///
		mgroups("Successful negotiation" "Reasons for not negotiating", pattern(1 0 0 1 0 0 0 0) ///
		prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cline{@span})) stats(N ymean, fmt(0 3) ///
		labels(`"N"' `"Y mean, males"')) mtitle("Cond" "Uncond" "Cond" "Not possible" "Not comfortable" "Useless" "Fear backlash" "Satisfied w/pay")

	
